﻿using JinJun.YShowReception.Core;
using JinJun.YShowReception.DAL.IRepository;
using JinJun.YShowReception.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JinJun.YShowReception.DAL.Repository
{
    public class SmsInfoRepository:ISmsInfoRepository
    {
       
        /// <summary>
        /// 添加短信发送记录
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int AddSmsInfo(SmsInfo smsInfo)
        {
            int result = -1;
            //sql语句
            string sql = "insert into SmsInfo(Code,TelPhone,CreateTime,ExpireTime) values(@Code,@TelPhone,@CreateTime,@ExpireTime)";
            smsInfo.CreateTime = DateTime.Now;
            smsInfo.ExpireTime = DateTime.Now.AddMinutes(5);         
            //调用添加方法
            return DapperHelper<SmsInfo>.Execute(sql, smsInfo);
        }


        /// <summary>
        /// 查询验证码是否存在
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int CheckCode(SmsInfo smsInfo)
        {
            int result = -1;
            //sql语句
            string sql = "select count(1) from SmsInfo where Code=@Code and TelPhone=@TelPhone and ExpireTime>@ExpireTime";
            smsInfo.ExpireTime = DateTime.Now;          
            //调用查询方法
            return Convert.ToInt32(DapperHelper<SmsInfo>.ExecuteScalar(sql,smsInfo));
        }
    }
}
